package com.zbl.zblproject.erp.service;


import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.pagehelper.PageInfo;
import com.zbl.zblproject.core.entity.*;
import com.zbl.zblproject.erp.entity.*;


import java.util.List;

/**
 * @author youlanqiang
 * @version 1.0
 * @date 2018/10/10
 *
 * 出入库订单数据层
 *
 */
public interface ErpOrderService {

    List<RepertoryVOByYSH> salesPageByYSHKC(long start, long end, int cat_id, int supplier_id,String goodsName);

    boolean updateErpOrderByContext(String orderSn, String context);

    /**
     * 获取ErpOrder
     * @param orderSn 订单号
     * @return
     */
    ErpOrder getErpOrder(String orderSn);

    /**
     * 创建出入库订单
     * @param order 订单
     * @param items 出入库商品
     * @return
     */
    ErpOrder createErpOrder(ErpOrder order, List<ErpOrderItem> items);


    /**
     * 查询类表
     * @param search
     * @param current 第几页
     * @param size   几项
     * @return
     */
    IPage<ErpOrder> erpOrderList(String search, int current, int size);

    /**
     * 订单状态通过
     * @param orderInfo 订单号
     * @param userId   用户ID
     * @return
     */
    ErpOrder passOrder(String orderInfo, int userId);



    /**
     * 订单状态回滚
     * @param orderInfo 订单号
     * @return
     */
    boolean rollbackOrder(String orderInfo);


    /**
     * 根据订单号查询订单物件
     * @param orderInfo 订单号
     * @return
     */
    List<ErpTempOrderItem> getOrderItemByOrder(String orderInfo);

    List<ErpTempOrderItem> getOrderItemByOrders(String orderInfo);

    List<ErpTempOrderItem> getOrderItemByOrderNotDesc(String orderInfo);

    /**
     * 根据订单号删除订单
     * @param id
     * @return
     */
    boolean deleteOrder(int id);


    /**
     * 查询订单 条件为订单不为Deliver的收货状态 并且项未出货的商品
     * @return
     */
    List<Order> getUserOrdersByNotDeliver(int deliver);


    List<Order> getUserOrdersByIsConfirm(int deliver);

    List<Order> getUserOrdersDesc();



    /**
     * 远程订单列
     * @param notin 不包含在里面的订单
     * @param user  用户
     * @return
     */
    List<Order> getRemoteOutOrder(List<String> notin, AdminUser user);


    /**
     * 查询订单 条件为订单不为Deliver的收货状态
     * @param deliver
     * @return
     */
    List<Supplier> getSupplierByNotDeliver(int pageCur,int pageSize,int deliver, int mode);





    /**
     * 查询订单
     * @param deliver
     * @param mode
     * @return
     */
    PageInfo getOrdersByNotDeliver(int pageCur,int pageSize,int deliver, int mode);

    /**
     * 根据OrderSn来查询ErpTempOrderItem
     * @param orderSn 订单的SN
     * @return
     */
    List<ErpTempOrderItem> getTempOrderByOrderSn(String orderSn);

    /**
     * 根据OrderSn来查询ErpTempOrderItem,但是不能存在OrderSn2
     * @param orderSn 订单的SN
     * @return
     */
    List<ErpTempOrderItem> getTempOrderByOrderSnAndNotPurchasing(String orderSn);

    /**
     * 获取欠缺货订单，格式和erpList一样
     * @param mode  欠货 or 缺货状态 0:欠货  1:缺货
     * @return
     */
    List<ErpOweItemList> getOweTtemListByMode(int mode,String orderSn,String start,String end);

    List<ErpOweItemList> getItemListForEnded();


    List<ErpTempOrderItem> getOweTempOrder(String orderSn, int mode);

    List<ErpOweItemList> getOweItemListByModeForFast(int mode,String orderSn,String start,String end);

    ErpTempOrderItem oweItem2TempItem(final ErpOweGoodsItem x, final ErpGoods goods, int index, int mode);


    void oweGoodsByIn(OrderItem orderItem, ErpOrderItem x, ErpOrder order, int userId, int supplierId);


    /**
     * 设置x的orderItem为以出库状态
     */
    void outStatusChange(OrderItem orderItem, ErpOrder order);

    /**
     * 缺货功能  /出库
     * 缺货不会直接减去数据库里的商品但是会记录下来.
     *
     * @param x     erpOrderItem
     * @param order erpOrder
     */
    void oweGoodsByOut(OrderItem orderItem, ErpOrderItem x, ErpOrder order, int userId, int supplierId);


    /**
     * 对仓库商品进行修改 如果存在便添加商品,如果不存在就创建商品
     *
     * @param item
     * @param x
     */
    void intserOrUpdateWarehouseItem(ErpWarehouseItem item, ErpOrderItem x);



    /**
     * 查询出所有的没有入库的订单
     *
     * @return
     */
    List<Order> ordersByCanUse(int pageCur,int pageSize,int deliver);

    PageInfo orderListPage(int pageCur,int pageSize,int deliver);

    List<Order> supplierOrdersByCanUseAndISConfirm(int deliver);

    PageInfo supplierOrdersByCanUse(int pageCur,int pageSize,int deliver);

    List<Order> supplierOrdersByCanUses(int deliver);

    /**
     * 根据OrderSn来查询没有入库的ErpTempOrderItem
     *
     * @param orderSn
     * @return
     */
    List<ErpTempOrderItem> getTempOrderByOrderSnAndNotInto(String orderSn);


    /**
     * 根据OrderSn来查询没有出库的ErpTempOrderItem
     *
     * @param orderSn
     * @return
     */
    List<ErpTempOrderItem> getTempOrderByOrderSnAndNotOut(String orderSn);


    ErpTempOrderItem orderItem2TempItem(OrderItem x);

    void insertOrderItemByOrderId(List<ErpOrderItem> items, int orderId, ErpOrder order);


    List<ErpOrder> selectErpOrderByBrandName(String brandName, int mode, int status);

    /**
     * 删除对应订单号
     * @param orderSn ERP订单号
     * @return true/false
     */
    boolean deleteErpOrder(String orderSn);

    /**
     * 生成一个欠货单，并将原始欠货单终结
     * @param orderSn
     * @return
     */
    boolean endedOwe(String orderSn, AdminUser user);

    /**
     * 入库单从完成状态回滚为草稿
     * @param orderSn orderSn
     * @return true/false
     */
    boolean rkBack(String orderSn);
}
